home *** CD-ROM | disk | FTP | other *** search
/ Amiga Plus Special 23 / AMIGAplus Sonderheft 23 (2000)(Falke)(DE)[!].iso / Tools / Packer / xad / Developer / Sources / clients / xDisk.c < prev    next >
C/C++ Source or Header  |  1999-11-06  |  5KB  |  177 lines

  1. #ifndef XADMASTER_XDISK_C
  2. #define XADMASTER_XDISK_C
  3.  
  4. /* Programmheader
  5.  
  6.     Name:        xDisk.c
  7.     Main:        xadmaster
  8.     Versionstring:    $VER: xDisk.c 1.0 (05.09.1998)
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    xDisk disk archiver client
  12.  
  13.  1.0   05.09.98 : first version
  14. */
  15.  
  16. #include <proto/xadmaster.h>
  17. #include <dos/dos.h>
  18. #include "SDI_compiler.h"
  19. #include "xpkstuff.c"
  20.  
  21. #ifndef XADMASTERFILE
  22. #define xDisk_Client        FirstClient
  23. #define NEXTCLIENT        0
  24. UBYTE version[] = "$VER: xDisk 1.0 (05.09.1998)";
  25. #endif
  26. #define XDISK_VERSION        1
  27. #define XDISK_REVISION        0
  28.  
  29. struct xDisk {
  30.   ULONG            xd_Header;    /* equals 'XDS0' */
  31.   struct DateStamp    xd_Date;    /* date of creation */
  32.   ULONG            xd_PackTime;    /* in seconds */
  33.   UWORD            xd_AttnFlags;    /* ExecBase->AttnFlags */
  34.   UWORD            xd_SoftVer;    /* ExecBase->SoftVer */
  35.   ULONG            xd_CylinderSize; /* Size of one cylinder */
  36.   ULONG            xd_NumCylinders; /* Number of cylinders */
  37.   ULONG            xd_InfoTextSize; /* no text == 0 */
  38.   ULONG            xd_LowCyl;    /* lowest crunched cylinder */
  39.   ULONG            xd_HighCyl;    /* highest crunched Cylinder */
  40. };
  41.  
  42. /* After tha xDisk structure the packed data follows. First the
  43.    XPK-Crunched info-text (when available) and the each cylinder as a
  44.    XPKF-block.
  45.    NOTE: It seems that sometimes xDisk adds xd_InfoTextSize, also when no
  46.    text was added!
  47. */
  48.  
  49. ASM(BOOL) xDisk_RecogData(REG(d0, ULONG size), REG(a0, STRPTR data),
  50. REG(a6, struct xadMasterBase *xadMasterBase))
  51. {
  52.   if(((ULONG *) data)[0] == 0x58445330)
  53.     return 1;
  54.   else
  55.     return 0;
  56. }
  57.  
  58. ASM(LONG) xDisk_GetInfo(REG(a0, struct xadArchiveInfo *ai),
  59. REG(a6, struct xadMasterBase *xadMasterBase))
  60. {
  61.   LONG err;
  62.   ULONG dat[9];
  63.   ULONG num = 0;
  64.   struct xDisk xd;
  65.   struct xadDiskInfo *xdi;
  66.  
  67.   if(!(xdi = (struct xadDiskInfo *) xadAllocObjectA(XADOBJ_DISKINFO, 0)))
  68.     return XADERR_NOMEMORY;
  69.   ai->xai_DiskInfo = xdi;
  70.  
  71.   if((err = xadHookAccess(XADAC_READ, sizeof(struct xDisk), &xd, ai)))
  72.     return err;
  73.   xdi->xdi_EntryNumber = 1;
  74.   xdi->xdi_Cylinders = xd.xd_NumCylinders;
  75.   xdi->xdi_LowCyl = xd.xd_LowCyl;
  76.   xdi->xdi_HighCyl = xd.xd_HighCyl;
  77.   xdi->xdi_SectorSize = 512; /* most devices should use 512 as blocksize */
  78.   xdi->xdi_CylSectors = xd.xd_CylinderSize>>9;
  79.   xdi->xdi_TotalSectors = xd.xd_NumCylinders*xdi->xdi_CylSectors;
  80.   xdi->xdi_Flags = XADDIF_GUESSHEADS|XADDIF_GUESSTRACKSECTORS;
  81.   if(xdi->xdi_CylSectors & 1)
  82.   {
  83.     xdi->xdi_Heads = 1;
  84.     xdi->xdi_TrackSectors = xdi->xdi_CylSectors;
  85.   }
  86.   else
  87.   {
  88.     xdi->xdi_Heads = 2;
  89.     xdi->xdi_TrackSectors = xdi->xdi_CylSectors>>1;
  90.   }
  91.  
  92.   while(ai->xai_InPos < ai->xai_InSize)
  93.   {
  94.     if((err = xadHookAccess(XADAC_READ, 36, dat, ai)))
  95.       return err;
  96.     if((err = xadHookAccess(XADAC_INPUTSEEK, dat[1]-28, 0, ai)))
  97.       return err;
  98.     ++num;
  99.     if(dat[8] & (1<<25)) /* check for password flag in every entry */
  100.     {
  101.       ai->xai_Flags |= XADAIF_CRYPTED;
  102.       xdi->xdi_Flags |= XADDIF_CRYPTED;
  103.     }
  104.   }
  105.   if((err = xadHookAccess(XADAC_INPUTSEEK, sizeof(struct xDisk) -
  106.   ai->xai_InPos, 0, ai)))
  107.     return err;
  108.   dat[0] = xdi->xdi_HighCyl+1-xdi->xdi_LowCyl;
  109.   if(num == dat[0]+1) /* decrunch infotext and store pointer */
  110.   {
  111.     xdi->xdi_Flags |= XADDIF_INFOTEXT;
  112.  
  113.     return xpkDecrunch(&xdi->xdi_InfoText, &xdi->xdi_InfoTextSize, ai,
  114.     xadMasterBase);
  115.   }
  116.   else if(num != dat[0])
  117.     return XADERR_ILLEGALDATA;
  118.  
  119.   return 0;
  120. }
  121.  
  122. ASM(LONG) xDisk_UnArchive(REG(a0, struct xadArchiveInfo *ai),
  123. REG(a6, struct xadMasterBase *xadMasterBase))
  124. {
  125.   LONG i, err = 0, u;
  126.   struct {
  127.     STRPTR a;
  128.     ULONG  s;
  129.   } dat;
  130.   struct ExecBase * SysBase = xadMasterBase->xmb_SysBase;
  131.  
  132.   u = ai->xai_InPos;
  133.  
  134.   /* skip entries */
  135.   for(i = ai->xai_CurDisk->xdi_LowCyl; !err && i < ai->xai_LowCyl; ++i)
  136.   {
  137.     if(!(err = xadHookAccess(XADAC_READ, 8, &dat, ai)))
  138.       err = xadHookAccess(XADAC_INPUTSEEK, dat.s, 0, ai);
  139.   }
  140.  
  141.   for(; !err && i <= ai->xai_HighCyl; ++i)
  142.   {
  143.     if(!(err = xpkDecrunch(&dat.a, &dat.s, ai, xadMasterBase)))
  144.     {
  145.       err = xadHookAccess(XADAC_WRITE, dat.s, dat.a, ai);
  146.       FreeVec(dat.a);
  147.     }
  148.   }
  149.  
  150.   /* seek back to start */
  151.   if(!err)
  152.     err = xadHookAccess(XADAC_INPUTSEEK, u-ai->xai_InPos, 0, ai);
  153.  
  154.   return err;
  155. }
  156.  
  157. ASM(void) xDisk_Free(REG(a0, struct xadArchiveInfo *ai),
  158. REG(a6, struct xadMasterBase *xadMasterBase))
  159. {
  160.   struct ExecBase * SysBase = xadMasterBase->xmb_SysBase;
  161.   if(ai->xai_DiskInfo)
  162.   {
  163.     if(ai->xai_DiskInfo->xdi_InfoText)
  164.       FreeVec(ai->xai_DiskInfo->xdi_InfoText);
  165.     xadFreeObjectA(ai->xai_DiskInfo, 0);
  166.     ai->xai_DiskInfo = 0; /* clear the entry */
  167.   }
  168. }
  169.  
  170. struct xadClient xDisk_Client = {
  171. NEXTCLIENT, XADCLIENT_VERSION, 1, XDISK_VERSION, XDISK_REVISION, 4,
  172. XADCF_DISKARCHIVER, XADCID_XDISK, "xDisk", (BOOL (*)()) xDisk_RecogData,
  173. (LONG (*)()) xDisk_GetInfo, (LONG (*)()) xDisk_UnArchive,
  174. (void (*)()) xDisk_Free};
  175.  
  176. #endif /* XADASTER_XDISK_C */
  177.